/*
 * @description: 公共api
 * @Author: jhw
 * @Date: 2023-05-07 19:59:18
 * @LastEditors: jhw
 * @LastEditTime: 2023-07-27 15:08:44
 */
import { ContentTypeEnum } from '@/enums/httpEnum';
import { http } from '@/utils/request/http';
import { ResBody } from '@/types/interface';

const prefix = '/api';

export const test = (data: any) => {
  return http.post<ResBody<unknown, true>>({ url: `${prefix}/user/login`, data });
};

export const test1 = () => {
  return http.get({
    url: `${prefix}test`,
    headers: {
      'Content-Type': ContentTypeEnum.JSON,
    },
  });
};

// 上传分片接口
export const uploadChunk = (data: any) => {
  return http.post({
    url: `${prefix}/upload_chunk`,
    data,
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
  });
};

// 分片合并接口
export const mergeChunk = (data: any) => {
  return http.post({
    url: `${prefix}/upload_merge`,
    data,
    headers: {
      'Content-Type': ContentTypeEnum.FORM_URLENCODED,
    },
  });
};

// 已经上传的分片
export const uploadedChunks = (params: any) => {
  return http.get({
    url: `${prefix}/upload_already`,
    params,
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
  });
};

/**
 * @description 单文件上传
 */
export const uploadFile = ({ data, onUploadProgress }: { data: any; onUploadProgress: any }) => {
  return http.post({
    url: `${prefix}/upload_single`,
    data,
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
    onUploadProgress,
  });
};
